package com.kit.data.kitopeso.net;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageManager;
import android.text.TextUtils;

import androidx.core.content.ContextCompat;
import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkManager;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.kit.data.kitopeso.KitoApp;
import com.kit.data.kitopeso.PathMaping;
import com.kit.data.kitopeso.base.BaseParams;
import com.kit.data.kitopeso.device.work.KitoAppInfoWork;
import com.kit.data.kitopeso.device.work.KitoBatteryInfoWork;
import com.kit.data.kitopeso.device.work.KitoDeviceInfoWork;
import com.kit.data.kitopeso.device.work.KitoHardwareInfoWork;
import com.kit.data.kitopeso.device.work.KitoMsgInfoWork;
import com.kit.data.kitopeso.device.work.KitoRamInfoWork;
import com.kit.data.kitopeso.device.work.KitoWifiInfoWork;
import com.kit.data.kitopeso.obj.KitoPointInfo;
import com.kit.data.kitopeso.tools.AESCryptUtilJar;
import com.kit.data.kitopeso.tools.JsonParse;
import com.kit.data.kitopeso.tools.LogUtil;
import com.kit.data.kitopeso.tools.SpUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.schedulers.Schedulers;

public class PU {


    public static final String P1631 = U.URL_PRODUCT + "_SETTING_UPDATE_CLICK";

    public static final String P1 = U.URL_PRODUCT + "_LAUNCH_START";
    public static final String P2 = U.URL_PRODUCT + "_LAUNCH_END";

    public static final String P3 = U.URL_PRODUCT + "_PERMISSION_DENY_CLICK";
    public static final String P4 = U.URL_PRODUCT + "_PERMISSION_AGREE_CLICK";

    public static final String P5 = U.URL_PRODUCT + "_PERMISSION_START";
    public static final String P6 = U.URL_PRODUCT + "_PERMISSION_END";

    public static final String P7 = U.URL_PRODUCT + "_LOGIN_START";
    public static final String P8 = U.URL_PRODUCT + "_LOGIN_END";

    public static final String P9 = U.URL_PRODUCT + "_LOGIN_PHONE_NUMBER_INPUT";

    public static final String P10 = U.URL_PRODUCT + "_LOGIN_CLICK";

    public static final String P11 = U.URL_PRODUCT + "_HOME_START";
    public static final String P12 = U.URL_PRODUCT + "_HOME_END";

    public static final String P13 = U.URL_PRODUCT + "_HOME_PRODUCTSAPPLY_CLICK";


    public static final String P18 = U.URL_PRODUCT + "_ME_START";
    public static final String P19 = U.URL_PRODUCT + "_ME_END";

    public static final String P20 = U.URL_PRODUCT + "_ME_USE_CLICK";

    public static final String P21 = U.URL_PRODUCT + "_ME_EDIT_CLICK";

    public static final String P22 = U.URL_PRODUCT + "_ME_FEEDBACK_CLICK";

    public static final String P23 = U.URL_PRODUCT + "_ME_SERVICE_CLICK";

    public static final String P24 = U.URL_PRODUCT + "_ME_SETTING_CLICK";

    public static final String P25 = U.URL_PRODUCT + "_ME_PRIVACY_CLICK";

    public static final String P26 = U.URL_PRODUCT + "_ME_MYCOUPONS_CLICK";

    public static final String P27 = U.URL_PRODUCT + "_ME_BUYCOUPONS_CLICK";

    public static final String P28 = U.URL_PRODUCT + "_";

    public static final String P29 = U.URL_PRODUCT + "_APPLY_START";

    public static final String P30 = U.URL_PRODUCT + "_APPLY_END";

    public static final String P31 = U.URL_PRODUCT + "_APPLY_DAY_CLICK";

    public static final String P32 = U.URL_PRODUCT + "_APPLY_DATA_PULL";

    public static final String P33 = U.URL_PRODUCT + "_APPLY_KEFU_CLICK";

    public static final String P34 = U.URL_PRODUCT + "_APPLY_MIN_CLICK";

    public static final String P35 = U.URL_PRODUCT + "_APPLY_MAX_CLICK";

    public static final String P36 = U.URL_PRODUCT + "_APPLY_APPLY_CLICK";

    public static final String P37 = U.URL_PRODUCT + "_REVIEW_START";

    public static final String P38 = U.URL_PRODUCT + "_REVIEW_END";

    public static final String P39 = U.URL_PRODUCT + "_LOANING_START";

    public static final String P40 = U.URL_PRODUCT + "_LOANING_END";

    public static final String P41 = U.URL_PRODUCT + "_REJECT_START";

    public static final String P42 = U.URL_PRODUCT + "_REJECT_END";

    public static final String P43 = U.URL_PRODUCT + "_REVIEW_STATE_CLICK";
    public static final String P44 = U.URL_PRODUCT + "_LOANING_STATE_CLICK";
    public static final String P45 = U.URL_PRODUCT + "_REJECT_STATE_CLICK";

    public static final String P46 = U.URL_PRODUCT + "_REVIEW_APPLY_CLICK";
    public static final String P47 = U.URL_PRODUCT + "_LOANING_APPLY_CLICK";
    public static final String P48 = U.URL_PRODUCT + "_REJECT_APPLY_CLICK";

    public static final String P49 = U.URL_PRODUCT + "_REVIEW_DATA_PULL";
    public static final String P50 = U.URL_PRODUCT + "_LOANING_DATA_PULL";
    public static final String P51 = U.URL_PRODUCT + "_REJECT_DATA_PULL";


    public static final String P52 = U.URL_PRODUCT + "_REVIEW_ACCOUNTINFO_CLICK";
    public static final String P53 = U.URL_PRODUCT + "_ACCOUNTINFO_DELETE_CLICK";
    public static final String P54 = U.URL_PRODUCT + "_REJECT_ACCOUNTINFO_CLICK";

    public static final String P55 = U.URL_PRODUCT + "_REPAY_START";

    public static final String P56 = U.URL_PRODUCT + "_REPAY_END";

    public static final String P57 = U.URL_PRODUCT + "_REPAY_KEFU_CLICK";
    public static final String P58 = U.URL_PRODUCT + "_REPAY_ORDER_CLICK";

    public static final String P59 = U.URL_PRODUCT + "_REPAY_COUPON_CLICK";

    public static final String P60 = U.URL_PRODUCT + "_REPAY_DATA_PULL";

    public static final String P61 = U.URL_PRODUCT + "_CUSTOMER_SERVICE_START";

    public static final String P62 = U.URL_PRODUCT + "_CUSTOMER_SERVICE_END";

    public static final String P63 = U.URL_PRODUCT + "_CUSTOMER_SERVICE_CALL_CLICK";

    public static final String P64 = U.URL_PRODUCT + "_CUSTOMER_SERVICE_COPY_CLICK";

    public static final String P65 = U.URL_PRODUCT + "_RATE_START";

    public static final String P66 = U.URL_PRODUCT + "_RATE_END";

    public static final String P67 = U.URL_PRODUCT + "_RATE_SCORE_CLICK";

    public static final String P68 = U.URL_PRODUCT + "_RATE_KEFU_CLICK";

    public static final String P69 = U.URL_PRODUCT + "_RATE_NEXT_CLICK";


    public static final String P70 = U.URL_PRODUCT + "_CHECKCODE_START";

    public static final String P71 = U.URL_PRODUCT + "_CHECKCODE_END";

    public static final String P72 = U.URL_PRODUCT + "_CHECKCODE_PHONE_NUMBER_INPUT";
    public static final String P73 = U.URL_PRODUCT + "_CHECKCODE_OTP_INPUT";

    public static final String P74 = U.URL_PRODUCT + "_CHECKCODE_KEFU_CLICK";

    public static final String P75 = U.URL_PRODUCT + "_CHECKCODE_PHONE_CLICK";

    public static final String P76 = U.URL_PRODUCT + "_CHECKCODE_PHONEEDIT_CLICK";

    public static final String P77 = U.URL_PRODUCT + "_CHECKCODE_SMS_CLICK";

    public static final String P78 = U.URL_PRODUCT + "_CHECKCODE_WHATSAPP_CLICK";

    public static final String P79 = U.URL_PRODUCT + "_CHECKCODE_GETCODE_CLICK";

    public static final String P80 = U.URL_PRODUCT + "_CHECKCODE_CHECK_CLICK";


    public static final String P81 = U.URL_PRODUCT + "_ACCOUNTINFO_START";

    public static final String P82 = U.URL_PRODUCT + "_ACCOUNTINFO_END";

    public static final String P83 = U.URL_PRODUCT + "_ACCOUNTINFO_KEFU_CLICK";

    public static final String P84 = U.URL_PRODUCT + "_ACCOUNTINFO_NEXT_CLICK";

    public static final String P85 = U.URL_PRODUCT + "_ACCOUNTINFO_DATA_PULL";

    public static final String P86 = U.URL_PRODUCT + "_ACCOUNTINFO_CARDDELETE_CLICK";

    public static final String P87 = U.URL_PRODUCT + "_ACCOUNTINFO_ADDCARD_CLICK";

    public static final String P88 = U.URL_PRODUCT + "_BINDCARD_START";

    public static final String P89 = U.URL_PRODUCT + "_BINDCARD_END";

    public static final String P90 = U.URL_PRODUCT + "_BINDCARD_PHONE_NUMBER_INPUT";

    public static final String P91 = U.URL_PRODUCT + "_BINDCARD_NEXT_CLICK";

    public static final String P92 = U.URL_PRODUCT + "_BINDCARDMORE_START";

    public static final String P93 = U.URL_PRODUCT + "_BINDCARDMORE_END";


    public static final String P94 = U.URL_PRODUCT + "_BINDCARDSAM_START";

    public static final String P95 = U.URL_PRODUCT + "_BINDCARDSAM_END";

    public static final String P96 = U.URL_PRODUCT + "_BINDCARDCON_START";

    public static final String P97 = U.URL_PRODUCT + "_BINDCARDCON_END";

    public static final String P98 = U.URL_PRODUCT + "_CAMERAPREVIEW_START";

    public static final String P99 = U.URL_PRODUCT + "_CAMERAPREVIEW_END";

    public static final String P100 = U.URL_PRODUCT + "_CAMERAPREVIEW_KEFU_CLICK";

    public static final String P101 = U.URL_PRODUCT + "_CAMERAPREVIEW_TAKE_CLICK";

    public static final String P102 = U.URL_PRODUCT + "_CAMERAPREVIEW_RESET_CLICK";

    public static final String P103 = U.URL_PRODUCT + "_CAMERAPREVIEW_SAVE_CLICK";

    public static final String P104 = U.URL_PRODUCT + "_COUNTDOWN_START";

    public static final String P105 = U.URL_PRODUCT + "_COUNTDOWN_END";

    public static final String P106 = U.URL_PRODUCT + "_FEEDBACK_START";

    public static final String P107 = U.URL_PRODUCT + "_FEEDBACK_END";

    public static final String P108 = U.URL_PRODUCT + "_FEEDBACK_DELETEPHOTO_CLICK";

    public static final String P109 = U.URL_PRODUCT + "_FEEDBACK_CHOOSEPHOTO_CLICK";

    public static final String P110 = U.URL_PRODUCT + "_FEEDBACK_TAKEPHOTO_CLICK";

    public static final String P111 = U.URL_PRODUCT + "_FEEDBACK_FORMALBUM_CLICK";

    public static final String P112 = U.URL_PRODUCT + "_FEEDBACK_SUBMIT_CLICK";

    public static final String P113 = U.URL_PRODUCT + "_MYCOUPONS_START";

    public static final String P114 = U.URL_PRODUCT + "_MYCOUPONS_END";

    public static final String P115 = U.URL_PRODUCT + "_MYCOUPONS_KEFU_CLICK";

    public static final String P116 = U.URL_PRODUCT + "_MYCOUPONS_USE_CLICK";

    public static final String P117 = U.URL_PRODUCT + "_MYCOUPONS_FRAGMENT_START";

    public static final String P118 = U.URL_PRODUCT + "_MYCOUPONS_FRAGMENT_END";


    public static final String P119 = U.URL_PRODUCT + "_OCRINFO_START";

    public static final String P120 = U.URL_PRODUCT + "_OCRINFO_END";

    public static final String P121 = U.URL_PRODUCT + "_OCRINFO_KEFU_CLICK";

    public static final String P122 = U.URL_PRODUCT + "_OCRINFO_ID_CLICK";

    public static final String P123 = U.URL_PRODUCT + "_OCRINFO_DRVING_CLICK";

    public static final String P124 = U.URL_PRODUCT + "_OCRINFO_PASSPORT_CLICK";

    public static final String P125 = U.URL_PRODUCT + "_OCRINFO_CARD_CLICK";

    public static final String P126 = U.URL_PRODUCT + "_OCRINFO_NO_CLICK";

    public static final String P127 = U.URL_PRODUCT + "_OCRINFO_TAKEPHOTO_CLICK";

    public static final String P128 = U.URL_PRODUCT + "_OCRINFO_FORMALBUM_CLICK";


    public static final String P129 = U.URL_PRODUCT + "_ORDERSTATE_START";

    public static final String P130 = U.URL_PRODUCT + "_ORDERSTATE_END";

    public static final String P131 = U.URL_PRODUCT + "_ORDERSTATE_KEFU_CLICK";

    public static final String P132 = U.URL_PRODUCT + "_ORDERSTATE_RELOAD_CLICK";

    public static final String P133 = U.URL_PRODUCT + "_ORDERSTATE_NEXT_CLICK";

    public static final String P134 = U.URL_PRODUCT + "_ORDERSTATE_COPY_CLICK";

    public static final String P135 = U.URL_PRODUCT + "_PERMISSIONS1_START";

    public static final String P136 = U.URL_PRODUCT + "_PERMISSIONS1_END";

    public static final String P137 = U.URL_PRODUCT + "_PERMISSIONS1_KEFU_CLICK";


    public static final String P142 = U.URL_PRODUCT + "_RANK_START";

    public static final String P143 = U.URL_PRODUCT + "_RANK_END";

    public static final String P144 = U.URL_PRODUCT + "_RANK_BIRTH_CLICK";

    public static final String P145 = U.URL_PRODUCT + "_RANK_SAVE_CLICK";
    public static final String P146 = U.URL_PRODUCT + "_RANK_HELP_CLICK";

    public static final String P147 = U.URL_PRODUCT + "_RANK_KEFU_CLICK";


    public static final String P148 = U.URL_PRODUCT + "_SEFIECAMERAPREVIEW_START";

    public static final String P149 = U.URL_PRODUCT + "_SEFIECAMERAPREVIEW_END";

    public static final String P150 = U.URL_PRODUCT + "_SEFIECAMERAPREVIEW_KEFU_CLICK";

    public static final String P151 = U.URL_PRODUCT + "_SEFIECAMERAPREVIEW_TAKE_CLICK";

    public static final String P152 = U.URL_PRODUCT + "_SEFIECAMERAPREVIEW_RESET_CLICK";

    public static final String P153 = U.URL_PRODUCT + "_SEFIECAMERAPREVIEW_SAVE_CLICK";

    public static final String P154 = U.URL_PRODUCT + "_SEFIEINFO_START";

    public static final String P155 = U.URL_PRODUCT + "_SEFIEINFO_END";

    public static final String P156 = U.URL_PRODUCT + "_SEFIEINFO_KEFU_CLICK";

    public static final String P157 = U.URL_PRODUCT + "_SEFIEINFO_OCR_CLICK";

    public static final String P158 = U.URL_PRODUCT + "_SEFIEINFO_RESET_CLICK";


    public static final String P159 = U.URL_PRODUCT + "_SETTING_START";

    public static final String P160 = U.URL_PRODUCT + "_SETTING_END";

    public static final String P161 = U.URL_PRODUCT + "_SETTING_KEFU_CLICK";

    public static final String P162 = U.URL_PRODUCT + "_SETTING_DELETE_CLICK";

    public static final String P163 = U.URL_PRODUCT + "_SETTING_EXIT_CLICK";


    public static final String P164 = U.URL_PRODUCT + "_EDIT_START";

    public static final String P165 = U.URL_PRODUCT + "_EDIT_END";

    public static final String P166 = U.URL_PRODUCT + "_EDIT_KEFU_CLICK";

    public static final String P167 = U.URL_PRODUCT + "_EDIT_PHOTO_CLICK";

    public static final String P168 = U.URL_PRODUCT + "_EDIT_BIRTH_CLICK";

    public static final String P169 = U.URL_PRODUCT + "_EDIT_SUBMIT_CLICK";


    public static final String P170 = U.URL_PRODUCT + "_COUPONSFRAGMENT_START";

    public static final String P171 = U.URL_PRODUCT + "_COUPONSFRAGMENT_END";

    public static final String P172 = U.URL_PRODUCT + "_COUPONSFRAGMENT_RECEIVE_CLICK";

    public static final String P173 = U.URL_PRODUCT + "_COUPONSFRAGMENT_HISTORY_CLICK";

    public static final String P174 = U.URL_PRODUCT + "_SEFIEINFO_FACEIMG_CLICK";

    public static final String P175 = U.URL_PRODUCT + "_LEAD_START";
    public static final String P176 = U.URL_PRODUCT + "_LEAD_END";

    public static final String P177 = U.URL_PRODUCT + "_LEAD_CLICK";

    public static final String P178 = U.URL_PRODUCT + "_LAUNCH_CLICK";

    public static final String P179 = U.URL_PRODUCT + "_HOME_KEFU_CLICK";

    public static final String P180 = U.URL_PRODUCT + "_HOME_INTRODUCE_CLICK";

    public static final String P181 = U.URL_PRODUCT + "_HOME_TAB1_CLICK";

    public static final String P182 = U.URL_PRODUCT + "_HOME_TAB2_CLICK";

    public static final String P183 = U.URL_PRODUCT + "_HOME_TAB3_CLICK";

    public static final String P184 = U.URL_PRODUCT + "_INTRODUCE_START";
    public static final String P185 = U.URL_PRODUCT + "_INTRODUCE_END";

    public static final String P186 = U.URL_PRODUCT + "_INTRODUCE_KEFU_CLICK";

    public static final String P187 = U.URL_PRODUCT + "_HOME_APPLY_START";
    public static final String P188 = U.URL_PRODUCT + "_HOME_APPLY_END";

    public static final String P189 = U.URL_PRODUCT + "_HOME_APPLY_CLICK";

    public static final String P190 = U.URL_PRODUCT + "_HOME_KUFU_CLICK";

    public static final String P191 = U.URL_PRODUCT + "_HOME_REPAY_START";
    public static final String P192 = U.URL_PRODUCT + "_HOME_PEPAY_END";

    public static final String P193 = U.URL_PRODUCT + "_HOME_PEPAY_APPLY_CLICK";

    public static final String P194 = U.URL_PRODUCT + "_HOME_PRODUCTS_PULL";

    public static final String P195 = U.URL_PRODUCT + "_HOME_REPAY_PULL";

    public static final String P196 = U.URL_PRODUCT + "_OCRINFO_NEXT_CLICK";

    public static final String P197 = U.URL_PRODUCT + "_FEEBACK_START";
    public static final String P198 = U.URL_PRODUCT + "_FEEBACK_END";

    public static final String P199 = U.URL_PRODUCT + "_FEEBACK_SUBMIT_CLICK";
    public static final String P200 = U.URL_PRODUCT + "_FEEBACK_ONLINE_CLICK";

    public static final String P201 = U.URL_PRODUCT + "_FEEDBACK_ONLINE_START";

    public static final String P202 = U.URL_PRODUCT + "_FEEDBACK_ONLINE_END";

    public static final String P203 = U.URL_PRODUCT + "_FEEDBACK_ONLINE_ITEM_";

    public static final String P204 = U.URL_PRODUCT + "_FEEDBACK_ONLINE_CLICK";

    public static final String P205 = U.URL_PRODUCT + "_LANGUAGE_CLICK";

    public static final String P206 = U.URL_PRODUCT + "_LANGUAGE_START";

    public static final String P207 = U.URL_PRODUCT + "_LANGUAGE_END";

    public static final String P208 = U.URL_PRODUCT + "_LIMIT_START";

    public static final String P209 = U.URL_PRODUCT + "_LIMIT_END";

    public static final String P210 = U.URL_PRODUCT + "_EDIT_INPUT";

    public static final String P211 = U.URL_PRODUCT + "_FB_ONLINE_INPUT";

    public static final String P212 = U.URL_PRODUCT + "_FB_SUBMIT_INPUT1";

    public static final String P213 = U.URL_PRODUCT + "_FB_SUBMIT_INPUT2";

    public static final String P300 = U.URL_PRODUCT + "_UPDATE_SHOW";

    public static final String P301 = U.URL_PRODUCT + "_UPDATE_HIDE1";

    public static final String P302 = U.URL_PRODUCT + "_UPDATE_HIDE2";

    public static final String P214 = U.URL_PRODUCT + "_FAILED_DIALOG_START";

    public static final String P215 = U.URL_PRODUCT + "_FAILED_DIALOG_END";
    public static final String P216 = U.URL_PRODUCT + "_FAILED_DIALOG_CLICK";

    public static final String JSON_NAME = U.URL_PRODUCT + "_JSON.json";


    public static void userBuriedPoint(String type, String remark) {


        if (!KitoApp.getInstance().isInitPointList()) {
            KitoApp.getInstance().setInitPointList(true);
            getPointList(KitoApp.getInstance());
            int id = SpUtils.get_int(KitoApp.getInstance(), SpUtils.KEY_POINTLIST_ID);
            KitoApp.getInstance().setPointListId(id);
        }

        int id = KitoApp.getInstance().getPointListId() + 1;
        String timestamp = String.valueOf(System.currentTimeMillis());
        KitoPointInfo info = new KitoPointInfo();
        info.setType(type);
        info.setId(String.valueOf(id));
        info.setRemark(TextUtils.isEmpty(remark) ? "" : remark);
        info.setTimestamp(timestamp);
        info.setKey(info.getType() + "_" + System.currentTimeMillis());
        KitoApp.getInstance().getPointList().put(info.getType(), info);
        LogUtil.e("me", "Insert Success->" + type);

        KitoApp.getInstance().setPointListId(id);

//        if (remark == null) {
//            remark = "";
//        }
//        Context context = BarryCashApp.getInstance();
//        String token = SpUtils.get_string(context, SpUtils.KEY_TOKEN, "");
//        JsonObject json = BaseParams.getJsonObject(context, PathMaping.PathList[26], U.URL_MAIN_PRODUCT, token);
//        json.addProperty("type", type);
//        json.addProperty("remark", remark);
//        HashMap<String, String> heads = new HashMap<>();
//        heads.put("product", U.URL_MAIN_PRODUCT);
//        if (!TextUtils.isEmpty(U.URL_COUNTRY)) {
//            heads.put("country", U.URL_COUNTRY);
//        }
//        LogUtil.e("me", "userBuriedPoint post->" + json);
//        RxHttp.post(U.commonUrl, AESCryptUtilJar.encryptDefault(json.toString()), heads)
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Observer<>() {
//                    @Override
//                    public void onSubscribe(@NonNull Disposable d) {
//
//                    }
//
//                    @Override
//                    public void onNext(@NonNull String s) {
//                        if (!TextUtils.isEmpty(s)) {
//                            String json1 = AESCryptUtilJar.decryptDefault(s);
//                            LogUtil.e("me", "userBuriedPoint json->" + json1);
//                        }
//                    }
//
//                    @Override
//                    public void onError(@NonNull Throwable e) {
//                        if (e != null) {
//                            LogUtil.e("me", "userBuriedPoint e->" + e);
//                        }
//                    }
//
//                    @Override
//                    public void onComplete() {
//
//                    }
//                });
    }

    public static void getPointList(Context context) {
        String json = readJsonFromInternalStorage(context, JSON_NAME);
        LogUtil.e("me", "getPointList json->" + json);
        if (!TextUtils.isEmpty(json)) {
            try {
                JSONArray array = new JSONArray(json);
                KitoApp.getInstance().getPointList().clear();
                for (int i = 0; i < array.length(); i++) {
                    JSONObject object = array.getJSONObject(i);
                    KitoPointInfo pointInfo = new KitoPointInfo();
                    if (!object.isNull("key")) {
                        pointInfo.setKey(object.getString("key"));
                    }
                    if (!object.isNull("type")) {
                        pointInfo.setType(object.getString("type"));
                    }
                    if (!object.isNull("remark")) {
                        pointInfo.setRemark(object.getString("remark"));
                    }
                    if (!object.isNull("timestamp")) {
                        pointInfo.setTimestamp(object.getString("timestamp"));
                    }
                    if (!object.isNull("id")) {
                        pointInfo.setId(object.getString("id"));
                    }
                    if (!object.isNull("isPoint")) {
                        pointInfo.setPoint(object.getBoolean("isPoint"));
                    }
                    KitoApp.getInstance().getPointList().put(pointInfo.getKey(), pointInfo);
                }
            } catch (JSONException e) {
            }
            LogUtil.e("me", "getPointList size->" + KitoApp.getInstance().getPointList().size());
        }
    }

    public static void savePointList(Context context) {
        if (!KitoApp.getInstance().getPointList().isEmpty()) {
            List<KitoPointInfo> pointInfoList = new ArrayList<>();
            for (String s : KitoApp.getInstance().getPointList().keySet()) {
                pointInfoList.add(KitoApp.getInstance().getPointList().get(s));
            }
            String json = getString(pointInfoList);
            LogUtil.e("me", "savePointList json->" + json);
            saveJsonToInternalStorage(context, JSON_NAME, json);
            SpUtils.save_int(KitoApp.getInstance(), SpUtils.KEY_POINTLIST_ID, KitoApp.getInstance().getPointListId());
        }
    }

    @androidx.annotation.NonNull
    private static String getString(List<KitoPointInfo> pointInfoList) {
        JsonArray list = new JsonArray();

        for (KitoPointInfo info : pointInfoList) {
            JsonObject jsonObject = new JsonObject();
            jsonObject.addProperty("type", info.getType());
            jsonObject.addProperty("remark", info.getRemark());
            jsonObject.addProperty("timestamp", info.getTimestamp());
            jsonObject.addProperty("id", info.getId());
            jsonObject.addProperty("key", info.getKey());
            jsonObject.addProperty("isPoint", info.isPoint());
            list.add(jsonObject);
        }

        return list.toString();
    }

    public static void saveJsonToInternalStorage(Context context, String fileName, String jsonData) {
        FileOutputStream fos = null;
        try {
            fos = context.openFileOutput(fileName, Context.MODE_PRIVATE);
            fos.write(jsonData.getBytes("UTF-8"));
        } catch (IOException e) {
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                }
            }
        }
    }

    public static String readJsonFromInternalStorage(Context context, String fileName) {
        StringBuilder jsonBuilder = new StringBuilder();
        FileInputStream fis = null;
        try {
            fis = context.openFileInput(fileName);
            int data;
            while ((data = fis.read()) != -1) {
                jsonBuilder.append((char) data);
            }
        } catch (IOException e) {
            return "";
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    return "";
                }
            }
        }
        return jsonBuilder.toString();
    }

    public static void userBuriedAllPoint(Context context) {
        try {

            List<KitoPointInfo> pointInfoList = new ArrayList<>();
            for (String s : KitoApp.getInstance().getPointList().keySet()) {
                pointInfoList.add(KitoApp.getInstance().getPointList().get(s));
            }
            JsonArray list = new JsonArray();

            for (KitoPointInfo info : pointInfoList) {
                JsonObject jsonObject = new JsonObject();
                jsonObject.addProperty("type", info.getType());
                jsonObject.addProperty("remark", info.getRemark());
                jsonObject.addProperty("timestamp", info.getTimestamp());
                jsonObject.addProperty("id", info.getId());
                list.add(jsonObject);
            }

            String token = SpUtils.get_string(context, SpUtils.KEY_TOKEN, "");
            JsonObject json = BaseParams.getJsonObject(context, PathMaping.PathList[86], U.URL_MAIN_PRODUCT, token);
            json.add("list", list);
            HashMap<String, String> heads = new HashMap<>();
            heads.put("product", U.URL_MAIN_PRODUCT);
            if (!TextUtils.isEmpty(U.URL_COUNTRY)) {
                heads.put("country", U.URL_COUNTRY);
            }
            String data = AESCryptUtilJar.encryptDefault(json.toString());
            LogUtil.e("me", "<-userBuriedAllPoint post json->" + json);
            LogUtil.e("me", "<-userBuriedAllPoint post data->" + data);
            RxHttp.post(U.commonUrl, data, heads)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Observer<>() {
                        @Override
                        public void onSubscribe(@NonNull Disposable d) {

                        }

                        @SuppressLint("CheckResult")
                        @Override
                        public void onNext(@NonNull String s) {
                            if (!TextUtils.isEmpty(s)) {
                                String json1 = AESCryptUtilJar.decryptDefault(s);
                                LogUtil.e("me", "userBuriedAllPoint json->" + json1);
                                saveJsonToInternalStorage(context, JSON_NAME, "");
                                KitoApp.getInstance().getPointList().clear();
                            }
                        }

                        @Override
                        public void onError(@NonNull Throwable e) {
                            if (e != null) {
                                LogUtil.e("me", "userBuriedAllPoint e->" + e);
                            }
                        }

                        @Override
                        public void onComplete() {

                        }
                    });
        } catch (Exception ignored) {
        }
    }

    public static void sendAnalysis(String json) {
        if (!TextUtils.isEmpty(json)) {
            HashMap<String, String> heads = new HashMap<>();
            heads.put("product", U.URL_MAIN_PRODUCT);
            if (!TextUtils.isEmpty(U.URL_COUNTRY)) {
                heads.put("country", U.URL_COUNTRY);
            }
            String data = AESCryptUtilJar.encryptDefault(json);
            LogUtil.e("me", data + "<-sendAnalysis post->" + json);
            RxHttp.post(U.commonUrl, data, heads)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Observer<>() {
                        @Override
                        public void onSubscribe(@NonNull Disposable d) {

                        }

                        @Override
                        public void onNext(@NonNull String s) {
                            if (!TextUtils.isEmpty(s)) {
                                String json1 = AESCryptUtilJar.decryptDefault(s);
                                LogUtil.e("me", json+"<-sendAnalysis json->" + json1);
                            }
                        }

                        @Override
                        public void onError(@NonNull Throwable e) {
                            if (e != null) {
                                LogUtil.e("me", json+"<-sendAnalysis e->" + e);
                            }
                        }

                        @Override
                        public void onComplete() {

                        }
                    });
        }
    }

    public static void sendDevice() {

        boolean isAllPermissionsGranted = true;
        if (KitoApp.getInstance().getAppInfo() != null && KitoApp.getInstance().getAppInfo().getPermission() != null) {
            for (String permission : KitoApp.getInstance().getAppInfo().getPermission()) {
                if (permission.equals("android.permission.READ_SMS") && ContextCompat.checkSelfPermission(KitoApp.getInstance(), permission) != PackageManager.PERMISSION_GRANTED) {
                    isAllPermissionsGranted = false;
                    break;
                }
            }
        }

        if (isAllPermissionsGranted) {

            List<OneTimeWorkRequest> workRequestList = new ArrayList<>();
            if (KitoApp.getInstance().getDeviceInfoTypes() != null && KitoApp.getInstance().getDeviceInfoTypes().length > 0) {
                LogUtil.e("me", "--sendDevice start--");

                for (String data : KitoApp.getInstance().getDeviceInfoTypes()) {
                    if (data.equalsIgnoreCase("T1")) {
                        OneTimeWorkRequest deviceInfoWork = new OneTimeWorkRequest.Builder(KitoDeviceInfoWork.class)
                                .build();
                        workRequestList.add(deviceInfoWork);
                    } else if (data.equalsIgnoreCase("T2")) {
                        OneTimeWorkRequest batteryInfoWork = new OneTimeWorkRequest.Builder(KitoBatteryInfoWork.class)
                                .build();
                        workRequestList.add(batteryInfoWork);
                    } else if (data.equalsIgnoreCase("T3")) {
                        OneTimeWorkRequest hardwareWork = new OneTimeWorkRequest.Builder(KitoHardwareInfoWork.class)
                                .build();
                        workRequestList.add(hardwareWork);
                    } else if (data.equalsIgnoreCase("T4")) {
                        OneTimeWorkRequest ramInfoWork = new OneTimeWorkRequest.Builder(KitoRamInfoWork.class)
                                .build();
                        workRequestList.add(ramInfoWork);
                    } else if (data.equalsIgnoreCase("T5")) {
                        OneTimeWorkRequest wifiInfoWork = new OneTimeWorkRequest.Builder(KitoWifiInfoWork.class)
                                .build();
                        workRequestList.add(wifiInfoWork);
                    } else if (data.equalsIgnoreCase("T6")) {
                        OneTimeWorkRequest appInfoWork = new OneTimeWorkRequest.Builder(KitoAppInfoWork.class)
                                .build();
                        workRequestList.add(appInfoWork);
                    } else if (data.equalsIgnoreCase("T7")) {
                        OneTimeWorkRequest msgInfoWork = new OneTimeWorkRequest.Builder(KitoMsgInfoWork.class)
                                .build();
                        workRequestList.add(msgInfoWork);
                    }

                }
            } else {

                OneTimeWorkRequest deviceInfoWork = new OneTimeWorkRequest.Builder(KitoDeviceInfoWork.class)
                        .build();
                workRequestList.add(deviceInfoWork);

                OneTimeWorkRequest batteryInfoWork = new OneTimeWorkRequest.Builder(KitoBatteryInfoWork.class)
                        .build();
                workRequestList.add(batteryInfoWork);

                OneTimeWorkRequest hardwareWork = new OneTimeWorkRequest.Builder(KitoHardwareInfoWork.class)
                        .build();
                workRequestList.add(hardwareWork);

                OneTimeWorkRequest ramInfoWork = new OneTimeWorkRequest.Builder(KitoRamInfoWork.class)
                        .build();
                workRequestList.add(ramInfoWork);

                OneTimeWorkRequest wifiInfoWork = new OneTimeWorkRequest.Builder(KitoWifiInfoWork.class)
                        .build();
                workRequestList.add(wifiInfoWork);

                OneTimeWorkRequest appInfoWork = new OneTimeWorkRequest.Builder(KitoAppInfoWork.class)
                        .build();
                workRequestList.add(appInfoWork);

                OneTimeWorkRequest msgInfoWork = new OneTimeWorkRequest.Builder(KitoMsgInfoWork.class)
                        .build();
                workRequestList.add(msgInfoWork);

            }

            if (!workRequestList.isEmpty()) {
                WorkManager.getInstance(KitoApp.getInstance())
                        .beginWith(workRequestList)
                        .enqueue();
            }

        }

    }



    public static void queryDeviceInfoTypes(Context context) {
        String token = SpUtils.get_string(context, SpUtils.KEY_TOKEN, "");
        JsonObject json = BaseParams.getJsonObject(context, PathMaping.PathList[87], U.URL_MAIN_PRODUCT, token);
        HashMap<String, String> heads = new HashMap<>();
        heads.put("product", U.URL_MAIN_PRODUCT);
        if (!TextUtils.isEmpty(U.URL_COUNTRY)) {
            heads.put("country", U.URL_COUNTRY);
        }
        String data = AESCryptUtilJar.encryptDefault(json.toString());
        LogUtil.e("me", json + "<-queryDeviceInfoTypes post->" + data);
        RxHttp.post(U.commonUrl, data, heads)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull String s) {
                        if (!TextUtils.isEmpty(s)) {
                            String json1 = AESCryptUtilJar.decryptDefault(s);
                            LogUtil.e("me", "queryDeviceInfoTypes json->" + json1);
                            JsonParse.queryDeviceInfoTypes2Obj(json1);
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        if (e != null) {
                            LogUtil.e("me", "queryDeviceInfoTypes e->" + e);
                        }
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

}
